<!-- 登录3			logincheck -->
<template>
	<view class="warps">
		<view class="w90">
			<view class="p_t_31">
				<text class="fs36 bold">其它手机号</text>
			</view>
		</view>
		<view class="m_t_30">
			<view class="fs14"
				style="width:680rpx;display: flex;margin: 0 auto;border-bottom: 2rpx solid #e7e7e7;height: 80rpx;line-height: 80rpx;padding-top: 20rpx;">
				<view style="width:95%;" class="flex-center f b">
					<input type="number" v-model="phone" class="ipts" placeholder="输入手机号码"
						placeholder-style="color:#999;" />
				</view>
			</view>
		</view>
		<view class="m_t_40">
			<view class="fs14"
				style="width:680rpx;display: flex;margin: 0 auto;border-bottom: 2rpx solid #e7e7e7;height: 80rpx;line-height: 80rpx;padding-top: 20rpx;">
				<view style="width:95%;" class="flex-center f b">
					<input type="number" v-model="yanzhengma" class="ipts" placeholder="短信验证码"
						placeholder-style="color:#999;" />
					<view @tap="yanzhen" class="hong"  :class="{'qx': suo==false}">
						{{tet}}
					</view>
				</view>
			</view>
		</view>
		
		<view class="logincheck-but" @click="gologin">
			<button type="default">登录</button>
		</view>
		<u-popup v-model="show" mode="center" width="80%" border-radius="20">
			<view class="center" >
				<view class="bb" style="height: 100rpx;line-height: 100rpx;">
					选择用户
				</view>
				<view class=" pb20 dis-flex flex-wrap">
					<view @click="gouser(item)" class="wd50 mt20" v-for="(item,index) in userList">
						<image :src="item.img" mode="" style="border-radius: 200rpx;width: 130rpx;height: 130rpx;"></image>
						<view class="c-999 fs26 mt5 ellipsis pl20 pr20">
							{{item.name}}
						</view>
					</view>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show:false,
				tet: '获取验证码',
				yanzhengma: '',
				phone:'',
				suo:true,
				time:59,
				loginResCode:'',
				show:false,
				userList:[]
			}
		},
		onLoad() {
			// 动态导航条文字
			uni.setNavigationBarTitle({
				title: '手机号登录'
			})
		},
		methods: {
			yanzhen() {
				if(this.phone == ''){
					this.$api.toast('请输入手机号')
					return false; 
				}
				if(!(/^1[3456789]\d{9}$/.test(this.phone))){
					this.$api.toast('手机号码不正确')
					return false; 
				} 
				if(this.suo == true){
					this.suo = false
					this.tet = this.time + "s"
					var interval = setInterval(()=>{
						this.time = this.time - 1
						this.tet = this.time + "s"
						if(this.time == -1){
							this.tet = "获取验证码"
							this.time = 60
							this.suo = true
							clearInterval(interval); 
						}
					},1000)
					var json={
						phone:this.phone,
					}
					this.$http.post(this.$config.UrlPostsendSms, json).then((res) => {
						if (res.code == 2) {
							var num = "";
							for (var i = 0; i < 6; i++) {
								num += Math.floor(Math.random() * 10)
							}
							setTimeout(() => {
								this.yanzhengma = num
							}, 2000)
						}
					})
					
				}
			
			},
			gologin(){
				var that = this
				if(that.yanzhengma == ''){
					that.$api.toast('请入验证码')
					return
				}
				if(that.phone == ''){
					that.$api.toast('请入新手机号码')
					return
				}
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						var json={
							code:loginRes.code,
							phone:that.phone,
							phonecode:that.yanzhengma,
							upid:uni.getStorageSync('scene')
						}
						that.$http.post(that.$config.UrlPostphoneLogin, json).then((res) => {
							if (res.status == 1) {
								if(res.userList.length > 1){
									that.userList = res.userList
									that.show = true
								}else{
									uni.setStorageSync('token', res.data);
									uni.removeStorageSync('scene');//登录成功后删除二维码里的参数
									that.$api.toast('登录成功')
									setTimeout(()=>{
										that.$api.openWindow('/pages/mine/mine','switchTab')
									},500)
								}
							}else{
								that.$api.toast(res.err)
							}
						})
					}
				});
				
			},
			//选择用户
			gouser(item){
				var that = this
				uni.login({
					provider: 'weixin',
					success: function(loginRes) {
						var json={
							code: loginRes.code,
							token:item.token
						}
						that.$http.post(that.$config.UrlPostselectUser, json).then((res) => {
							if (res.status == 1 ) {
								uni.setStorageSync('token', item.token);
								that.$api.toast('登录成功')
								setTimeout(()=>{
									that.$api.openWindow('/pages/mine/mine','switchTab')
								},500)
							}
						})
					}
				});
				
				
			}
		}
	}
</script>

<style scoped>
	.qx{
		background-color: #d1d1d1!important;
	}
	.ipts {
		border: 0px;
		font-weight: 400;
		font-size: 30rpx;
		height: 100%;
		width: 100%;
		font-size:24rpx;
	}
	.hong {
		width: 180rpx;
		height: 52rpx;
		border-radius: 8rpx;
		background-color: #1f73f2;
		font-size: 24rpx;
		font-weight: 400;
		color: #fff;
		line-height: 52rpx;
		text-align: center;
	}
	.logincheck-but{
		margin-top:60rpx;
	}
	.logincheck-but>button{
		width: 686rpx;
		height: 66rpx;
		line-height:66rpx;
		opacity: 1;
		background: #1f73f2;
		border-radius: 16rpx;
		font-size: 24rpx;
		color: #ffffff;
	}
</style>
